package com.cbs.android.extension.recyclerviewadapter;

import android.support.v7.widget.GridLayoutManager;

/**
 * Created by broche on 8/10/16.
 */
public class RecyclerViewSpanSizeLookup extends GridLayoutManager.SpanSizeLookup {
    private final RecyclerViewAdapter adapter;
    private final GridLayoutManager layoutManager;

    public RecyclerViewSpanSizeLookup(RecyclerViewAdapter adapter, GridLayoutManager layoutManager) {
        this.adapter = adapter;
        this.layoutManager = layoutManager;
    }

    @Override
    public int getSpanSize(int position) {
        boolean isHeader = adapter.isHeaderView(position);
        boolean isEmpty = adapter.isEmptyView(position);
        return (isHeader || isEmpty) ? layoutManager.getSpanCount() : 1;
    }
}
